home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / StoneTable folder / SampleTables / source.tbl < prev   
Text File  |  1992-03-28  |  10KB  |  230 lines

  1. # options, grid lines, title height/width, title style\
  2. O 131913\
  3. G\
  4. X 30,60\
  5. B 30,50\
  6. S helvetica,12,1,0,0,0\
  7. # set style for future cells and titles\
  8. s -1,-1,monaco,9,0,0,0,1\
  9. # add and set columns titles and widths\
  10. C 3\
  11. W 0,50\
  12. W 1,50\
  13. W 2,200\
  14. T 0,From\
  15. T 1,Subject\
  16. T 2,Text\
  17. # add and set row titles and heights\
  18. R 5\
  19. # set cells\
  20. c 0,0,jackiw@cs.swarthmore.edu\
  21. c 1,0,Subject: Re: List Manager advice\
  22. c 2,0,rdd@walt.cc.utexas.edu (Robert Dorsett) writes:
  23.  
  24. > I'm attempting to use the List Manager, from within a dialog, to implement a 
  25. > one-column list of text cells.  The length of the list can vary, with items 
  26. > My problem is that I'm unable to get the cell ID of the currently-selected
  27. > item.  I'm convinced I'm adding data to the list correctly list correctly 
  28. > (dataBounds for the list looks okay), but if I try LLast to get the point, it 
  29. > doesn't work.  If, on the other hand, I use LGetSelect, the numbers are too 
  30. > high (but not by much, which raises the maddening question of whether I'm 
  31. > installing the data correctly).  
  32. > Robert Dorsett                                   
  33.  
  34. I assume from your post that your list permits only one item to be selected at a time. Good.
  35.  
  36. begin {Modal List Dialog}
  37.  theDLOG:=GetNewDialog(theDLOG_Id,nil,pointer(-1));
  38.  InstallUserItem(theDLOG,List_ITEM,@DrawList);
  39.  SetPort(theDLOG);
  40.  
  41.  {At this point, it's assumed the list already exists; you've done LNew}
  42.  
  43.  theList^^.SelFlags:=lOnlyOne;
  44.  
  45.  ShowWindow(theDLOG);
  46.  LDoDraw(true,theList);
  47.  
  48.  repeat
  49.   ModalDialog(@ModalProc,itemHit);
  50.   if itemHit=List_Item then   {Translate double-clicks into Opens}
  51.    if LClick(GlobalPt,0,theList) then itemHit:=Open_ITEM; 
  52.  until (itemHit=Open_ITEM) or (itemHit=Cancel_ITEM);
  53.  
  54. if itemHit=open_ITEM then 
  55.  begin {Figure out which item is selected; that's what we want to open}
  56.   SetPt(aPt,0,0);
  57.   junk:=LGetSelect(true,aPt,theList);
  58.   aStr:='#####################';
  59.   oldLen:=length(aStr);
  60.   LGetCell(ptr(longint(@aStr)+1),oldLen,aPt,theList);
  61.  
  62. {aStr now contains the text of your item to be opened; act appropriately}
  63.  ...
  64.  end;
  65. end;
  66.  
  67.  
  68. This scheme uses a global variable, globalPt, to record the coordinates of the last mousedown (that's the purpose of modalProc), so that our main loop, above, can send that point to the list manager for double-clicks.  (Alternately, doubleClicks could be detected in the filterProc, which would obviate the need for a global.)
  69.  
  70. If this doesn't help, why don't you post your code? 
  71.  
  72.  
  73. -- 
  74.        Nick Jackiw  
  75. \
  76. c 0,1,From: amanda@mermaid.intercon.com (Amanda Walker;)\
  77. c 1,1,Subject: Re: .c2.List Bummers Revisited (simple custom ldef with code)\
  78. c 2,1,In article <cZVSJ9i00WB2Q63mcX@andrew.cmu.edu>, es2q+@andrew.cmu.edu (Erik Warren Selberg) writes:
  79.  
  80. > Is there any way to access
  81. > variables in the main program from an LDEF, and if so, how??!
  82.  
  83. Well, they way I do it is to have a baby LDEF that, by default, just draws a string they way LDEF 0 does, but if the list's refCon is non-zero, treats it as a pointer to a function and calls it to do the drawing. All you have to do is make sure A5 is set correctly.
  84.  
  85. Here's the source for the LDEF in MPW C 3.0, taken in its entirety from known working code.  It does contain "the cast from Hell," but hey :-).
  86.  
  87. ----------------------
  88. /*
  89.     Simple Custom LDEF
  90.  
  91.     Amanda Walker, InterCon Corporation
  92.     6 October 1988
  93.  
  94.     This is a very simple custom LDEF.  It acts just like LDEF 0 if the refCon
  95.     field of the list is 0.  If it is non-zero, the LDEF treats it as the
  96.     address of a routine to call to actually draw a list element.
  97.  
  98. */
  99.  
  100. #include <Quickdraw.h>
  101. #include <Lists.h>
  102. #include <OSUtils.h>
  103.  
  104. #define nil ((void *) 0L)
  105.  
  106. pascal void STUBLDEF(lMessage, lSelect, lRect, lCell, lDataOffset, lDataLen,
  107.        lHandle)
  108. short lMessage;
  109. Boolean lSelect;
  110. Rect *lRect;
  111. Cell *lCell;
  112. short lDataOffset, lDataLen;
  113. ListHandle lHandle;
  114. {
  115.     char *p;
  116.     long savedA5;
  117.  
  118.     /* Make sure A5 is valid so the draw code can use its globals. */
  119.     savedA5 = SetCurrentA5();
  120.  
  121.     p = (char *) 0x938;  /* HiliteMode for color QD */
  122.     lMessage--;   /* no initialization */
  123.     if (!lMessage--) 
  124.     {  /* draw the cell */
  125.       if ((**lHandle).refCon)
  126.        (*((pascal void (*)(Rect *, Cell *, short, short, ListHandle))
  127.          (**lHandle).refCon))(lRect, lCell, lDataOffset, lDataLen,
  128.          lHandle);
  129.       else 
  130.         {
  131.         MoveTo(lRect->left + 5, lRect->top + 12);
  132.         HLock((**lHandle).cells);
  133.         DrawText(*((**lHandle).cells), lDataOffset, lDataLen);
  134.         HUnlock((**lHandle).cells);
  135.         }
  136.     if (lSelect) 
  137.        {
  138.        *p = *p & 0x7f;
  139.        InvertRect(lRect);
  140.        }
  141.     } 
  142.     else 
  143.     if (!lMessage--) 
  144.       { /* toggle highlighting */
  145.       *p = *p & 0x7f;
  146.       InvertRect(lRect);
  147.       }
  148.     SetA5(savedA5);  /* no closing code */
  149. }
  150.  
  151. If you don't know how to build code resources with MPW C, take a look at the examples in the CExamples directory.
  152.  
  153. Hope this helps,
  154.  
  155. Amanda Walker InterCon Systems Corporation\
  156. c 0,2,From: tim@hoptoad.uucp (Tim Maroney;)\
  157. c 1,2,Subject: Re:.c2. List Bummers Revisited (and Debugging Help)\
  158. c 2,2,In article <cZVSJ9i00WB2Q63mcX@andrew.cmu.edu> es2q+@andrew.cmu.edu (Erik Warren Selberg) writes:
  159. >ok... I finally fixed the clicking bug (by SetPorting every time I checked
  160. >if the application was mine (& thus did something with it).
  161.  
  162. Great, send me a million dollars now.
  163.  
  164. >I'd like to put the data object I have (called TFile, an object with a bunch
  165. >of neat stuff contained) into the list instead of using up 100 bytes a shot
  166. >as I am now... I've tried putting it in using StripAddress, putting in the
  167. >starting file (well, a pointer to the starting file) in the list's refCon and
  168. >trying to access it from there, and nothing.  Is there any way to access
  169. >variables in the main program from an LDEF, and if so, how??!  what am I doing
  170. >wrong?
  171.  
  172. I don't know; once again, your report has been far too vague to allow any solid deductions or even founded speculations.  "And nothing" is no more a report of a symptom that is "I don't feel so hot".  You can store common data structures in the list's refCon or in the list's userHandle.  These are then accessible by the LDEF through the list handle it is passed, and by the application through the list handle it is keeping track of.  What's the problem?  Does the refCon come out as zero or some other invalid value in the LDEF?  Then you're not stashing the value correctly.  The syntax would be "list^^.refCon = LONGINT(<whatever>);" if I remember my Pascal.
  173.  
  174. >also:  is there any way to debug an LDEF (or any code resource) from LSP?
  175. >this trial & error stuff is rather depressing!
  176.  
  177. Lots of ways.  First, to debug on the Mac, you simply must learn a low level debugger, such as MacsBug or TMON.  You can debug anything this way.  David Oster just gave a description of the process.  Briefly, place a Debugger instruction (0xa9ff) in your code at the point where you want to start watching the fun, and then step through.  It helps to have a paper listing of your program so you can follow along better.
  178.  
  179. You can also track the general flow of execution in various other ways.  If you're not sure a piece of code is getting executed, put a SysBeep in it.  And so on.
  180.  
  181. If you simply can't live without a symbolic debugger, then you use a pass-through code resource.  Your actual LDEF resource is six bytes, starting with the word for a JMP.L instruction with an absolute long operand (0x4ef9), and having the address of your definition procedure in the second and third words.  You link the definition procedure (the LDEF code) with your application, and set up the six-byte LDEF resource with the address of the main LDEF routine before you create your list, making sure it's non-purgeable so it won't get refeshed from disk. Then you can put symbolic breakpoints in your LDEF to your heart's content.  After it's debugged sufficiently, you can make it a real, separate LDEF again if you wish -- or you can leave it the way it is.
  182. -- 
  183. Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com\
  184. c 0,3,From: olson@bootsie.UUCP (Eric Olson;)\
  185. c 1,3,Subject: Re: List definitions and fonts...\
  186. c 2,3,In article <4715@helios.ee.lbl.gov> beard@ux1.lbl.gov (Patrick C Beard) writes:
  187. >In article <36618@cornell.UUCP> wayner@cs.cornell.edu (Peter Wayner) writes:
  188. >#I just built a scrolling list of names in my window
  189. >#and it works fine. I would like to change the font
  190. >#of the list, though, to be something other than
  191. >#the application font. I can't seem to find the 
  192. >#correct way to do this.
  193. >#
  194. >
  195. >What I do is bracket all of my calls to the list manager that do drawing
  196. >with calls to TextFont and TextSize with the appropriate font and size.
  197. >Then, I restore the old font and size to whatever is needed.  This
  198. >seems to work.
  199.  
  200. If you change the font after the list has been drawn, you may wish to set the indent field of the List Record.  The LDEF sets this during the init message, but then doesn't expect the font to change.  Something like:
  201.  
  202.     GetFontInfo(&fontinfo);
  203.     (*macList)->indent.h = 4;
  204.     (*macList)->indent.v = fontinfo.ascent;
  205.  
  206. These are the values that Apple's LDEF 0 chooses at list init time.
  207.  
  208. Note that you only need to change this if the font in the list changes dynamically, not if you just change it before calling LNew.
  209.  
  210. -Eric\
  211. c 0,4,From: ech@cbnewsk.att.com (ned.horvath)\
  212. c 1,4,Subject: Re: Cdevs and the List Manager\
  213. c 2,4,From article <13580@unix.SRI.COM>, by mxmora@unix.SRI.COM (Matt Mora):
  214.  
  215. > ...The whole idea of
  216. > the update routine is to only draw what really needs to be updated. Not to 
  217. > invalidate the whole mess and redraw it.
  218. > Does anybody know the real reason why the listmanager sometimes doesn't
  219. > update correctly? 
  220.  
  221. To add a bit more fuel to this thread: I've noticed that LUpdate does a ValidRect on the part of the window where the horizontal scrollbar is drawn -- even if the list has no horizontal scrollbar.  I traced this one through the 6.0.5 PACK0 code: sure enough, it tests for the presence of a scrollbar, then (if there isn't one), branches around the draw routine to the ValidRect.
  222.  
  223. If LUpdate is only being called between BeginUpdate and EndUpdate, this doesn't matter.  But if LUpdate is being called after resizing the list, this is annoying.  The only workaround I've found is to explicitly call InvalRect after LUpdate.  I have not checked to see if the same problem exists when there is no vertical scrollbar.
  224.  
  225. =.i.Ned Horvath;=\
  226. # turn on drawing mode\
  227. D\
  228.